package com.example.fragmentapptest2;

import android.os.Bundle;
//import android.app.Fragment;
import android.support.v4.app.Fragment;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ScrollView;
import android.widget.TextView;

public class DetailsFragment extends Fragment
{
	/**
	 * Create a new instance of DetailsFragment, initialized to
	 * show the text at 'index'.
	 */
	public static DetailsFragment newInstance(int index) 
	{
		DetailsFragment f = new DetailsFragment();
		
		// Supply index input as an argument
		Bundle args = new Bundle();
		args.putInt("index", index);
		f.setArguments(args);
		
		return f;
	}
	
	public int getShowIndex()
	{
		// Fragment.getArguments() returns a Bundle object
		// Bundle.getInt() returns the value associated with key "index" 
		// 0 is the default value if key does not exists
		return getArguments().getInt("index", 0);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, 
			Bundle savedInstanceState)
	{
		// Fragment.getActivity() returns the Activity this 
		// fragment is currently associated with
		
		ScrollView scroller = new ScrollView(getActivity());
		TextView text = new TextView(getActivity());
		int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 
				4, getActivity().getResources().getDisplayMetrics());
		
		text.setPadding(padding, padding, padding, padding);
		scroller.addView(text);
		text.setText(Sessions.DIALOGUE[getShowIndex()]);
		return scroller;
	}
}
